﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using System.ComponentModel;

namespace Negocio
{
    public class Group : PersistentObject ,IDataErrorInfo
    {
        private ObservableCollection<Player> players;
        private string name;


        public Group()
        {
            this.players = new ObservableCollection<Player>();
            this.name = "";            
        }

        public ObservableCollection<Player> Players
        {
            get { return this.players; }
            set { this.players = value; }
        }

        public string Name
        {
            get { return this.name; }
            set { this.name = value; }
        }

        public bool addPlayer(Player onePlayer)
        {
            bool ret = false;
            if (!this.players.Contains(onePlayer))
            {
                this.players.Add(onePlayer);                
                ret = true;
            }
            return ret;
        }

        public void deletePlayer(Player onePlayer)
        {
            this.players.Remove(onePlayer);            
        }

        public override bool Equals(object obj)
        {
            return this.Name.Equals((((Group)obj).Name));
        }        

        public string Error
        {
            get
            {
                return null;
            }
        }
        public string this[string name]
        {
            get
            {
                string result = null;
                if (name == "Name")
                {
                    if (this.name=="")
                    {
                        result = "Ingrese el nombre del Grupo.";
                    }
                }
                return result;
            }
        }

        public override int GetHashCode()
        {
            return base.GetHashCode();
        }
    }
}
